package io.renren.modules.app.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.app.entity.AppProductCategoryEntity;
import io.renren.modules.app.entity.dto.AppProductWithChildrenDTO;
import io.renren.modules.app.service.AppProductCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 产品分类
 *
 * @author LuoShun
 * @email lori6166@163.com
 * @date 2021-11-12 15:19:30
 */
@Api(tags = "App商品分类接口")
@RestController
@RequestMapping("/app/productCategory")
public class AppProductCategoryController {
    @Autowired
    private AppProductCategoryService appProductCategoryService;

    /**
     * 获取商品分类列表
     */
    @ApiOperation("获取商品分类列表")
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
//        System.out.println(params.toString());
//        return R.ok();
        PageUtils page = appProductCategoryService.queryPage(params);
        return R.ok().put("page",page);
    }

    /**
     * 根据id获取商品分类
     */
    @ApiOperation("根据id获取商品分类")
    @GetMapping("/{id}")
    public R getItem(@PathVariable Long id) {
        AppProductCategoryEntity appProductCategoryEntity = appProductCategoryService.getById(id);
        return R.ok().put("data",appProductCategoryEntity);
    }

    /**
     * 获取商品一级分类和二级分类下拉列表数据
     */
    @ApiOperation("获取商品一级分类和二级分类下拉列表数据")
    @GetMapping("/list/withChildren")
    public R getWithChildren(){
        List<AppProductWithChildrenDTO> list = appProductCategoryService.getWithChildren();
        return R.ok().put("data",list);
    }

}
